<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Swipe Detection</title>
  <style>
    #swipeArea {
      width: 100vw;
      height: 100vh;
      background-color: #f0f0f0;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 24px;
      color: #333;
    }
  </style>
</head>
<body>
  <div id="swipeArea">Swipe Here</div>
  <script>
    const swipeArea = document.getElementById('swipeArea');

    let startX = 0, startY = 0;

    swipeArea.addEventListener('touchstart', (e) => {
      // 记录起点坐标
      startX = e.touches[0].clientX;
      startY = e.touches[0].clientY;
    });

    swipeArea.addEventListener('touchend', (e) => {
      // 获取终点坐标
      const endX = e.changedTouches[0].clientX;
      const endY = e.changedTouches[0].clientY;

      // 计算水平和垂直位移
      const deltaX = endX - startX;
      const deltaY = endY - startY;

      // 判断滑动方向
      if (Math.abs(deltaX) > Math.abs(deltaY)) {
        if (deltaX > 50) {
          alert('Right Swipe');
        } else if (deltaX < -50) {
          alert('Left Swipe');
        }
      } else {
        if (deltaY > 50) {
          alert('Down Swipe');
        } else if (deltaY < -50) {
          alert('Up Swipe');
        }
      }
    });
  </script>
</body>
</html>
